﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using LinkCard.Utils;
using System.Text;
using LinkCard.CustomerView.Common;

namespace LinkCard.CustomerView.Controls
{
    public partial class Adv : System.Web.UI.UserControl
    {
        public AppEnv _Instance = AppEnv.Instance();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                DataTable dt = DataHelper.SelectTable("Select * from ads where isActive = 1 order by AdPosition", false);
                StringBuilder sb = new StringBuilder();
                sb.Append("<table class=\"tableAdv\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");

                foreach (DataRow row in dt.Rows)
                {

                    string sAdLink, sAdFilePath;
                    sAdFilePath = _Instance["AdsFolderPath"] + row["AdFilePath"].ToString();
                    sAdLink = row["AdLink"].ToString();
                    

                    if (row["AdFilePath"].ToString().Contains(".swf"))
                    {
                        sb.Append("<tr> <td valign='top'><embed  width='220' src='" + sAdFilePath + "' wmode='transparent' quality='high'    pluginspage='http://www.macromedia.com/go/getflashplayer'        type='application/x-shockwave-flash'>   </td></tr>");

                    }
                    else
                    {
                        sb.Append("<tr><td valign='top'><img onclick=javascript:window.open('" + sAdLink + "') src='" + sAdFilePath + "'  style='border-width:0px;cursor:pointer'  width='220' /></td> </tr>");

                    }
                }
                sb.Append(" </table>");
                ltrText.Text = sb.ToString();
            }
        }
    }
}